//
//  UIView+HUD.m
//  RaiyiCommon
//
//  Created by zhiwei ma on 12-4-25.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "UIView+HUD.h"
#import "MBProgressHUD.h"

#define RYCMBHUDViewTag 9998
@implementation UIView (HUD)
- (void)showHUD
{
    MBProgressHUD* hud = (MBProgressHUD*)[self viewWithTag:RYCMBHUDViewTag];
    if (hud)
    {
        [self bringSubviewToFront:hud];
        return;
    }
    
    hud =[MBProgressHUD showHUDAddedTo:self animated:YES];
    hud.tag = RYCMBHUDViewTag;
}

- (void)showHUD:(NSString*)aText
{
    MBProgressHUD* hud = (MBProgressHUD*)[self viewWithTag:RYCMBHUDViewTag];
    if (hud)
    {
        [self bringSubviewToFront:hud];
        return;
    }
    
    hud =[MBProgressHUD showHUDAddedTo:self animated:YES];
    hud.labelText = aText;
    hud.tag = RYCMBHUDViewTag;
}

- (void)hideHUD
{
    [MBProgressHUD hideHUDForView:self animated:YES];
}

- (BOOL)hasHUD
{
    MBProgressHUD* hud = (MBProgressHUD*)[self viewWithTag:RYCMBHUDViewTag];
    return hud ? YES : NO;
}
@end
